package org.springframework.beans;

import org.springframework.beans.PropertyValue;
import org.springframework.beans.PropertyValues;

import java.util.ArrayList;
import java.util.List;

public class MutablePropertyValues implements PropertyValues {

    private final List<PropertyValue> propertyValueList;

    public MutablePropertyValues() {
        propertyValueList = new ArrayList<>(0);
    }

    public MutablePropertyValues(PropertyValues original) {
        if (original != null) {
            PropertyValue[] pvs = original.getPropertyValues();
            propertyValueList = new ArrayList<>(pvs.length);
            for (PropertyValue pv : pvs) {
                propertyValueList.add(pv);
            }
        } else {
            propertyValueList = new ArrayList<>(0);
        }
    }

    public void addPropertyValue(PropertyValue propertyValue) {
        this.propertyValueList.add(propertyValue);
    }

    @Override
    public PropertyValue[] getPropertyValues() {
        return propertyValueList.toArray(new PropertyValue[0]);
    }

    public boolean isEmpty() {
        return propertyValueList.size() == 0;
    }
}
